const App = getApp();
const wxParse = require('../../wxParse/wxParse.js')
const siteinfo = require('../../siteinfo.js')


Page({

  data: {
    // 页面参数
    options: {},
    // 页面元素
    items: {},
    scrollTop: 0,
    detail: {},
    XianChangZhaoPian: [],
    GongZuoZhaoPian: [],
    WenTiZhaoPian: [],
    article: '',
    IsGongshui: '有',
    addr: {},
    SYId: '',
    JianChaRiQi: '',
    tuResult: true, //检测一下是不是有没有图片未传完
    guancaiList: [{
        value: '灰口铸铁管'
      },
      {
        value: '镀锌钢管'
      },
      {
        value: '钢管'
      },
      {
        value: 'PVC'
      },
      {
        value: 'PPR'
      },
      {
        value: 'PE'
      },
      {
        value: '不锈钢'
      }
    ],
    TianQiList: [{
        value: '晴天'
      },
      {
        value: '阴天'
      },
      {
        value: '雨天'
      },
    ],
    ZhuBaBaDingList: [{
        value: '裂缝'
      },
      {
        value: '异常变形'
      },
      {
        value: '积水'
      },
      {
        value: '杂草'
      },
      {
        value: '正常'
      },
    ],
    JinBaShuiMianList:[
      {
        value: '冒泡'
      },
      {
        value: '变浑'
      },
      {
        value: '旋涡'
      },
      {
        value: '垃圾'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaFangLangQiangList: [{
        value: '开裂'
      },
      {
        value: '挤碎'
      },
      {
        value: '架空'
      },
      {
        value: '错断'
      },
      {
        value: '倾斜'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaYingShuiPoList: [{
        value: '损坏'
      },
      {
        value: '裂缝'
      },
      {
        value: '剥落'
      },
      {
        value: '滑动'
      },
      {
        value: '隆起'
      },
      {
        value: '塌坑'
      },
      {
        value: '冲刷'
      },
      {
        value: '杂草'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBeiShuiPoList: [{
        value: '裂缝'
      },
      {
        value: '剥落'
      },
      {
        value: '滑动'
      },
      {
        value: '隆起'
      },
      {
        value: '塌坑'
      },
      {
        value: '雨林沟'
      },
      {
        value: '散浸'
      },
      {
        value: '冒水'
      },
      {
        value: '渗水'
      },
      {
        value: '流土'
      },
      {
        value: '管涌'
      },
      {
        value: '护坡不完整'
      },
      {
        value: '杂草'
      },
      {
        value: '兽洞'
      },
      {
        value: '蚁穴'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBaZhiList: [{
        value: '滑动'
      },
      {
        value: '隆起'
      },
      {
        value: '塌坑'
      },
      {
        value: '散浸'
      },
      {
        value: '冒水'
      },
      {
        value: '渗水'
      },
      {
        value: '流土'
      },
      {
        value: '管涌'
      },
      {
        value: '兽洞'
      },
      {
        value: '蚁穴'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBaMianPaiShuiXiTongList: [{
        value: '未设'
      },
      {
        value: '裂缝'
      },
      {
        value: '损坏'
      },
      {
        value: '淤塞'
      },
      {
        value: '杂草'
      },
      {
        value: '反破'
      },
      {
        value: '坝后填平'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaDaoShenJiangYaSheBeiList: [{
        value: '未设'
      },
      {
        value: '损坏'
      },
      {
        value: '堵塞'
      },
      {
        value: '淹没'
      },
      {
        value: '掩埋'
      },
      {
        value: '渗水骤增骤减'
      },
      {
        value: '渗水浑浊'
      },
      {
        value: '坝后填平'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBaJiList: [ //主芭吧唧
      {
        value: '渗漏水：水量骤增'
      },
      {
        value: '渗漏水：浑浊'
      },
      {
        value: '基础廊道：未设；'
      },
      {
        value: '基础廊道：裂缝；'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaLiangAnBaQiangList: [{
        value: '坝体与岸坡连接处：错动'
      },
      {
        value: '坝体与岸坡连接处：开裂'
      },
      {
        value: '坝体与岸坡连接处：渗水'
      },
      {
        value: '两岸坝端区：裂缝'
      },
      {
        value: '滑动'
      },
      {
        value: '滑坡'
      },
      {
        value: '崩塌'
      },
      {
        value: '溶蚀'
      },
      {
        value: '隆起'
      },
      {
        value: '塌坑'
      },
      {
        value: '异常渗水'
      },
      {
        value: '蚁穴'
      },
      {
        value: '兽洞'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBaDuanAnPoList: [{
        value: '坝端岸坡：裂缝'
      },
      {
        value: '坝端岸坡：塌滑'
      },
      {
        value: '护坡：隆起；'
      },
      {
        value: '护坡：塌陷；'
      },
      {
        value: '护坡：损坏；'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBaZhiJinQuList: [{
        value: '阴湿'
      },
      {
        value: '渗水'
      },
      {
        value: '管涌'
      },
      {
        value: '流土'
      },
      {
        value: '隆起'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaBaHouPaiShuiXiTongList: [{
        value: '未设'
      },
      {
        value: '损坏'
      },
      {
        value: '堵塞'
      },
      {
        value: '淹没'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaShouYouPuGaiList: [{
        value: '裂缝'
      },
      {
        value: '塌坑'
      },
      {
        value: '不变检查口'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaPoMianList: [{
        value: '冲刷'
      },
      {
        value: '开裂'
      },
      {
        value: '崩塌'
      },
      {
        value: '滑移'
      },
      {
        value: '正常'
      },
    ],
    ZhuBaPoMianZhiHuJieGouList: [{
        value: '变形'
      },
      {
        value: '裂缝'
      },
      {
        value: '错位'
      },
      {
        value: '正常'
      },
    ],
    ShuiDongYinShuiDuanList: [{
        value: '未设'
      },
      {
        value: '裂缝'
      },
      {
        value: '堵塞'
      },
      {
        value: '淤泥'
      },
      {
        value: '崩塌'
      },
      {
        value: '不便检查'
      },
      {
        value: '正常'
      },

    ],
    ShuiDongJinShuiTaList: [{
        value: '未设'
      },
      {
        value: '裂缝'
      },
      {
        value: '渗水'
      },
      {
        value: '空浊'
      },
      {
        value: '倾斜'
      },
      {
        value: '不均匀沉降'
      },
      {
        value: '正常'
      },
    ],
    ShuiDongDongShenList: [{
        value: '裂缝'
      },
      {
        value: '崩塌'
      },
      {
        value: '鼓起'
      },
      {
        value: '渗水'
      },
      {
        value: '空浊'
      },
      {
        value: '放水时间内声响异常'
      },
      {
        value: '不便检查'
      },
      {
        value: '正常'
      },
    ],
    ShuiDongChuShuiKouList: [{
        value: '水流形态异常'
      },
      {
        value: '流量异常'
      },
      {
        value: '周边渗漏'
      },
      {
        value: '管内漏水'
      },
      {
        value: '裂缝'
      },
      {
        value: '塌滑'
      },
      {
        value: '正常'
      },
    ],
    ShuiDongXiaoNengGongList: [{
        value: '未设'
      },
      {
        value: '冲刷'
      },
      {
        value: '磨损'
      },
      {
        value: '淘刷'
      },
      {
        value: '淤积'
      },
      {
        value: '杂物堆积'
      },
      {
        value: '排水孔堵塞'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoJinShuiDuanList: [{
        value: '坍塌'
      },
      {
        value: '崩岸'
      },
      {
        value: '淤堵'
      },
      {
        value: '有阻水障碍'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoShangYouHuPoList: [{
        value: '冲刷'
      },
      {
        value: '开裂'
      },
      {
        value: '崩塌'
      },
      {
        value: '滑移'
      },
      {
        value: '变形'
      },
      {
        value: '裂缝'
      },
      {
        value: '错位'
      },
      {
        value: '表面排水设施堵塞'
      },
      {
        value: '排水孔堵塞'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoKongZhiDuanList: [{
        value: '闸墩：未设'
      },
      {
        value: '闸墩：裂缝'
      },
      {
        value: '闸墩：渗水'
      },
      {
        value: '闸墩：剥落'
      },
      {
        value: '闸墩：冲刷'
      },
      {
        value: '闸墩：磨损'
      },
      {
        value: '闸墩：空蚀'
      },
      {
        value: '边墙：裂缝'
      },
      {
        value: '边墙：渗水'
      },
      {
        value: '边墙：剥落'
      },
      {
        value: '边墙：冲刷'
      },
      {
        value: '边墙：磨损'
      },
      {
        value: '边墙：空蚀'
      },
      {
        value: '边墙：伸缩范围破损'
      },
      {
        value: '边墙：排水口破损'
      },
      {
        value: '底板：裂缝'
      },
      {
        value: '底板：渗水'
      },
      {
        value: '底板：剥落'
      },
      {
        value: '底板：冲刷'
      },
      {
        value: '底板：磨损'
      },
      {
        value: '底板：空蚀'
      },
      {
        value: '底板：伸缩范围破损'
      },
      {
        value: '溢流面：裂缝'
      },
      {
        value: '溢流面：渗水'
      },
      {
        value: '溢流面：剥落'
      },
      {
        value: '溢流面：冲刷'
      },
      {
        value: '溢流面：磨损'
      },
      {
        value: '溢流面：空蚀'
      },
      {
        value: '溢流面：有阻水障碍物'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoXiayouYiQiangList: [{
        value: '冲刷'
      },
      {
        value: '开裂'
      },
      {
        value: '崩塌'
      },
      {
        value: '滑移'
      },
      {
        value: '变形'
      },
      {
        value: '裂缝'
      },
      {
        value: '错位'
      },
      {
        value: '裂缝'
      },
      {
        value: '错位'
      },
      {
        value: '表面排水设施堵塞'
      },
      {
        value: '排水孔堵塞'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoXiaoNengGongList: [{
        value: '未设'
      },
      {
        value: '裂缝'
      },
      {
        value: '冲刷'
      },
      {
        value: '磨损'
      },
      {
        value: '淘刷'
      },
      {
        value: '淤积'
      },
      {
        value: '杂物堆积'
      },
      {
        value: '排水孔堵塞'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoZhaMenList: [{
        value: '闸门：未设'
      },
      {
        value: '闸门：变形'
      },
      {
        value: '闸门：裂纹'
      },
      {
        value: '闸门：脱焊'
      },
      {
        value: '闸门：锈蚀'
      },
      {
        value: '闸门：损坏'
      },
      {
        value: '闸门：启闭不灵活'
      },
      {
        value: '闸门：止水设施破损'
      },
      {
        value: '闸门：吊点结构不牢固'
      },
      {
        value: '闸门：不便检查'
      },
      {
        value: '门槽：未设'
      },
      {
        value: '门槽：卡堵'
      },
      {
        value: '门槽：气蚀'
      },
      {
        value: '开度指示器：未设'
      },
      {
        value: '开度指示器：不清晰'
      },
      {
        value: '开度指示器：不准确'
      },
      {
        value: '螺秆：未设'
      },
      {
        value: '螺秆：锈蚀'
      },
      {
        value: '螺秆：裂缝'
      },
      {
        value: '螺秆：弯曲'
      },
      {
        value: '钢丝绳/节链：未设'
      },
      {
        value: '钢丝绳/节链：锈蚀'
      },
      {
        value: '钢丝绳/节链：断丝'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoDongLiXiTongList: [{
        value: '未设'
      },
      {
        value: '电源异常'
      },
      {
        value: '备用电源不可靠'
      },
      {
        value: '传动异常'
      },
      {
        value: '制动'
      },
      {
        value: '限位不准确'
      },
      {
        value: '正常'
      },
    ],

    YiHongDaoQiBiJiList: [{
        value: '滑移异常'
      },
      {
        value: '手动启闭不可靠'
      },
      {
        value: '锈蚀'
      },
      {
        value: '破损'
      },
      {
        value: '启闭房内杂物堆积'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoJiaoTongQiaoList: [{
        value: '未设'
      },
      {
        value: '不均匀沉陷'
      },
      {
        value: '裂缝'
      },
      {
        value: '断裂'
      },
      {
        value: '正常'
      },
    ],
    YiHongDaoXiaYouHeChuangList: [{
        value: '河床'
      },
      {
        value: '无河道'
      },
      {
        value: '淤积'
      },
      {
        value: '堵塞'
      },
      {
        value: '泄洪能力不足'
      },
      {
        value: '正常'
      },
    ],
    LiangShuiYanList: [{
        value: '未设'
      },
      {
        value: '不规范'
      },
      {
        value: '损坏'
      },
      {
        value: '未观测'
      },
      {
        value: '正常'
      },
    ],
    CeYaGuanList: [{
        value: '未设'
      },
      {
        value: '不规范'
      },
      {
        value: '损坏'
      },
      {
        value: '未观测'
      },
      {
        value: '正常'
      },
    ],
    BiaoMianBianXingList: [{
        value: '未设'
      },
      {
        value: '不规范'
      },
      {
        value: '损坏'
      },
      {
        value: '未观测'
      },
      {
        value: '正常'
      },
    ],
    ShuiChiList: [{
        value: '未设'
      },
      {
        value: '损坏'
      },
      {
        value: '不能正常使用'
      },
      {
        value: '不规范'
      },
      {
        value: '正常'
      },
    ],
    YuLiangJiList: [{
        value: '未设'
      },
      {
        value: '损坏'
      },
      {
        value: '不能正常使用'
      },
      {
        value: '正常'
      },
    ],
    JiaoTongDaoLuList: [{
        value: '损坏'
      },
      {
        value: '不能通车'
      },
      {
        value: '正常'
      },
    ],
    BiaoShiPaiList: [{
        value: '损坏'
      },
      {
        value: '不全'
      },
      {
        value: '破旧'
      },
      {
        value: '正常'
      },
    ],
    GuanLiChangSuoWeiShengList: [{
        value: '破损'
      },
      {
        value: '脏乱'
      },
      {
        value: '正常'
      },
    ],
    ShuiKuPeiTaoList: [{
        value: '破损'
      },
      {
        value: '老化'
      },
      {
        value: '正常'
      },
    ],
    XianChangFangHongList: [{
        value: '无'
      },
      {
        value: '不全'
      },
      {
        value: '正常'
      },
    ],
    DangAnGuanLiList: [{
        value: '无上墙制度'
      },
      {
        value: '无档案管理室'
      },
      {
        value: '管理不规范'
      },
      {
        value: '正常'
      },
    ],
    JiaoTongDaoLuList: [{
        value: '不能通车'
      },
      {
        value: '损坏'
      },
      {
        value: '正常'
      },
    ],
    FengBiGuanLiList: [{
      value: '周边护栏缺失'
    },
    {
      value: '封闭管理存在漏洞'
    },
    {
      value: '正常'
    },]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  getDetail(e) {
    let _this = this
    App._get("GetShiYaoProjectInfo", {
      id: e,
      userId: wx.getStorageSync('user_id') ? wx.getStorageSync('user_id') : ''
    }, (res) => {
      console.log(res)
      _this.setData({
        detail: res
      })
      wxParse.wxParse('article', 'html', res.YaoQiu, _this, 0)
    })
  },
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      JianChaRiQi: e.detail.value
    })
  },
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  selectAddress() {
    App.getPermission(this)
  },
  formSubmit(e) {
    var _this = this
    console.log(e)
    let data = {
      ...e.detail.value
    }
    try {
      if (_this.data.loading) {
        return
      }

      if (!_this.data.tuResult) {
        wx.showModal({
          cancelColor: 'cancelColor',
          showCancel: false,
          title: '',
          content: '图片上传中，请稍后提交'
        })
        return
      }

      _this.setData({
        loading: true
      })
      data.JianChaRiQi = this.data.JianChaRiQi
      data.XianChangZhaoPian = this.data.XianChangZhaoPian.join(",")
      data.GongZuoZhaoPian = this.data.GongZuoZhaoPian.join(",")
      data.WenTiZhaoPian = this.data.WenTiZhaoPian.join(",")
      for(const i in data){
        if(Array.isArray(data[i])&&data[i].length!==0){
          console.log(1)
          data[i] = data[i].join(",")
        }
      }
      console.log(data,'data')
    } catch (e) {
      wx.showModal({
        cancelColor: 'cancelColor',
        showCancel: false,
        title: '错误',
        content: 'e'
      })
    }

    // for(let i in data){
    //   if(data[i] === ''){
    //     wx.showToast({
    //       title: '有选项未填写',
    //     })
    //     return
    //   }
    // }
    // data.SYId = this.data.SYId
    wx.showLoading({
      title: '提交中',
    })
    console.log(data)
    App._post_form(e.detail.target.dataset.xingwei == "tijiao" ? 'ShuiKuShenHe' : 'SaveShuiKuXunCha', data, (res) => {
      this.setData(_this.data.$data)
      wx.showModal({
        title: res,
        showCancel: false,
        complete: () => {
          // wx.navigateBack()
          _this.setData({
            loading: false
          })
        }
      })
    }, () => {}, () => {
      wx.hideLoading()
    })
  },
  shanchu(e) {
    //  e.target.name
    let _this = this
    console.log(e)
    let arr = []
    arr = arr.concat(_this.data[e.target.dataset.name])
    arr.splice(e.target.dataset.index, 1)
    this.setData(_this.setKeyAndValue(e.target.dataset.name, arr))
  },
  setKeyAndValue(key, value) {
    var obj = {};
    console.log(key)
    obj[key] = value
    console.log(obj)
    return obj
  },
  bindXianChangZhaoPian() {
    let _this = this
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.XianChangZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            XianChangZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  searchQingkong(e) {
    let _this = this;
    App._get('GetQingXiJiGou', {
      name: e.detail.value
    }, (res) => {
      console.log(res)
      if (res.length === 0) {
        res = [{
          Name: '暂无数据'
        }]
      }
      _this.setData({
        qingkongList: res
      })
    })
  },
  selectQingkong(e) {
    this.setData({
      qingkongList: [],
      ErGongSheShiQingXiJiGou: e.currentTarget.dataset.name
    })
  },
  bindGongZuoZhaoPian() {
    let _this = this
    var GongZuoZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.GongZuoZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            GongZuoZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  bindWenTiZhaoPian() {
    let _this = this
    var WenTiZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.WenTiZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            WenTiZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  goBottom() {
    console.log(1)
    var obj = wx.createSelectorQuery();
    obj.selectAll('.container').boundingClientRect(function (rect) {
      wx.pageScrollTo({
        scrollTop: rect[0].height,
        duration: 300
      });
    })
    obj.exec();

  },

  /**
   * 分享当前页面
   */
  onShareAppMessage() {
    let _this = this;
    return {
      title: _this.data.detail.Name,
      path: `/pages/detail/index?id=${_this.data.detail.CategaryId}`,
    };
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function () {
    // 获取首页数据
    wx.stopPullDownRefresh();
  }
});